package com.tanhua.server.Controller;

import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    //查询推荐列表
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(@RequestParam(defaultValue = "1") Integer page,
                                         @RequestParam(defaultValue = "10") Integer pageSize
    ) {
        PageResult vo = tanhuaService.recommendation(page,pageSize);
        return ResponseEntity.ok(vo);
    }

    //今日佳人
    @GetMapping("/todayBest")
    public ResponseEntity todayBest(){
        TodayBest vo = tanhuaService.todayBest();
        return ResponseEntity.ok(vo);
    }

    //佳人信息
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long userId){
        //1. 接收参数（用户id）

        //2. 调用service方法，返回佳人信息
        TodayBest vo = tanhuaService.personalInfo(userId);
        //3. 返回参数
        return ResponseEntity.ok(vo);
    }

    //查询陌生人问题
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId){
        String content = tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(content);
    }

    //回复陌生人问题
    @PostMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(@RequestBody Map map){
        //1. 获取参数
        String string = map.get("userId").toString();
        Long userId = Long.valueOf(string);
        String reply = map.get("reply").toString();
        //2. 调用service
        tanhuaService.reply(userId,reply);
        return ResponseEntity.ok(null);
    }

    //搜索附近
    @GetMapping("/search")
    public ResponseEntity search(String gender,String distance){
        //1. 调用方法获取集合对象
        List<NearUserVo> vos = tanhuaService.search(gender,distance);
        //2. 返回信息
        return ResponseEntity.ok(vos);
    }

}
